/*
 *	Copyright (C) 2008 - Mauricio Bieze Stefani
 *	This file is part of the Insano Game Engine.
 *
 *	Insano is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	Insano is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with Insano.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef GUIDEFS_H_INCLUDED
#define GUIDEFS_H_INCLUDED

#include <irrlicht.h>
#include <string>
#include <cstdarg>

#ifdef _WIN32
	#define swprintf _snwprintf
	#define vswprintf _vsnwprintf
#endif

#define MAX_TEXT_SIZE 200

const int ID_WELCOME_WINDOW 		=	100;	// window
const int ID_WELCOME_WINDOW_OK		=	101;	// button
const int ID_WELCOME_WINDOW_SKIP	=	102;	// checkbox

const int ID_LOGIN_WINDOW			=	200;	// window
const int ID_LOGIN_BUTTON			=	201;	// button
const int ID_LOGIN_CREATE_ACC		=	202;	// button
const int ID_LOGIN_HOST				=	203;	// editbox
const int ID_LOGIN_PORT				=	204;	// editbox
const int ID_LOGIN_USER				=	205;	// editbox
const int ID_LOGIN_PASS				=	206;	// editbox

const int ID_PROGRESS_WINDOW		=	300;	// window
const int ID_PROGRESS_TEXT			=	301;	// static text

const int ID_CHAR_WINDOW			=	400;	// window
const int ID_CHAR_COMBO				=	401;	// combobox
const int ID_CHAR_NEW				=	402;	// editbox
const int ID_CHAR_BUTTON			=	403;	// buttom

const int ID_CHAT_WINDOW			=	500;	// window
const int ID_CHAT_EDIT				=	501;	// editbox
const int ID_CHAT_LOG				=	502;	// listbox

std::string wc2str(const wchar_t *wc);
int wc2int(const wchar_t *wc);

class GUIManager
{
	public:
		irr::gui::IGUIEnvironment *env;
		irr::core::dimension2d<irr::s32> screenSize;
		irr::core::position2d<irr::s32> screenCenter;

		GUIManager() : env(NULL) {}
		virtual ~GUIManager() {}

		inline void updateScreenSize()
			{
				screenSize=env->getVideoDriver()->getScreenSize();
				screenCenter.X=screenSize.Width/2;
				screenCenter.Y=screenSize.Height/2;
			}

		inline irr::gui::IGUIElement * getElement(int id) const
			{ return env->getRootGUIElement()->getElementFromId(id, true); }
		inline void setFocus(int id)
			{ if(irr::gui::IGUIElement *e=getElement(id)) env->setFocus(e); }
		inline void setVisible(int id, bool visible)
			{ if(irr::gui::IGUIElement *e=getElement(id)) e->setVisible(visible); }
		inline bool isVisible(int id) const
			{
				if(irr::gui::IGUIElement *e=getElement(id))
					return e->isVisible();
				return false;
			}

		inline void setText(int id, const std::string& txt)
			{ setText(id, txt.c_str()); }

		void setText(int id, const char* txt, ...);
		void setText(int id, const wchar_t* txt, ...);

		const char* getText(int id) const;

		void appendText(int id, const char* txt, ...);

		void moveToScreenCenter(int id);
	private:
};

#endif // GUIDEFS_H_INCLUDED
